15. CODE: Check for Valid Neighbors
Check for Valid Neighbors
L2 Check For Valid Neighbors
Nice work, you are almost done with your program! The last part of the A* algorithm to be implemented is the part that adds neighboring nodes to the open vector. In order to expand your A* search from the current node to neighboring nodes, you first will need to check that neighboring grid cells are not closed, and that they are not an obstacle. In this exercise, you will write a function CheckValidCell
that does exactly this.
To Complete This Exercise:
Write a function
bool CheckValidCell
that accepts twoints
for the x and y coordinates and a reference to thegrid
. The function should do two things:
- Check that the (x, y) coordinate pair is on the grid.
- Check that the grid at (x, y) is
kEmpty
(this is the default case if the grid cell is notkClosed
or akObstacle
).
If both of these conditions are true, thenCheckValidCell
should returntrue
. Otherwise, it should returnfalse
.
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: generic
- Opened files (when workspace is loaded): n/a
-
userCode:
export CXX=g++-7
export CXXFLAGS=-std=c++17
g++() {
/usr/bin/g++-7 -std=c++17 "$1"
}
export -f g++